import React, { Component, createRef } from 'react'
import Chlid from './child'

export default class index extends Component {
  inputRef = createRef()
  ChildRef = createRef()

  componentDidMount () {
    this.inputRef.current.focus()
  }
  render () {
    return (
      <div>
        index
        <p>
          <input type='text' ref={this.inputRef} />
        </p>
        <Chlid ref={this.ChildRef} />
        <p>
          <button
            onClick={() => {
              this.ChildRef.current.setState({ fruit: '香蕉' })
            }}
          >
            change
          </button>
        </p>
      </div>
    )
  }
}
